<template>
	<view>
		
		
		<!-- <view @click="expGX">
			输出工序
		</view> -->
		<view style="display: flex;flex-direction: row;">
			<view @click="appendPeoPle()">
				加载人员
			</view><view @click="appendDev()">
				加载设备
			</view>历史数据<input v-model="historyPrefix" type="text" placeholder="2-11类似"/>
		</view>
		<view class="uni-container" v-if="typeSelected=='1'">
			<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
				@selection-change="selectionChange">
				<uni-thead>
					<uni-tr>

						<uni-th width="150" align="center">
							<select v-model="selected" @change="handleSelectChange">
								<option v-for="option in options" :value="option.value" :key="option.value">
									类型：{{ option.text }}
								</option>
							</select></uni-th>
						<uni-th width="150" align="center">
							分组方式
							<select v-model="typeSelected" @change="handleStypeSelectChange">
								<option v-for="option in typeOptions" :value="option.value" :key="option.value">
									{{ option.text }}
								</option>
							</select>
						</uni-th>
						<uni-th align="center">
							<view @click="exportToExcel">导出Excel</view>
						</uni-th>
						<uni-th width="204" align="center">

							<view @click="exportAllToExcel">All导出Excel</view>
						</uni-th>
					</uni-tr>

				</uni-thead>
				<uni-tr>
					<uni-th width="150" align="center">日期</uni-th>
					<uni-th width="150" align="center">员工</uni-th>
					<uni-th align="center">机台</uni-th>
					<uni-th width="204" align="center">工序</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.date }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.name }}</view>
					</uni-td>
					<uni-td align="center">{{ item.address }}</uni-td>
					<uni-td align="center">
						{{ item.group }}
					</uni-td>
				</uni-tr>




			</uni-table>
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent"
					:total="total" @change="change" /></view>
		</view>
		<view class="uni-container" v-else-if="typeSelected=='2'">
			<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
				@selection-change="selectionChange">
				<uni-thead>
					<uni-tr>
						<uni-th width="150" align="center">
							<select v-model="selected" @change="handleSelectChange">
								<option v-for="option in options" :value="option.value" :key="option.value">
									类型：{{ option.text }}
								</option>
							</select></uni-th>
						<uni-th width="150" align="center">
							分组方式
							<select v-model="typeSelected" @change="handleStypeSelectChange">
								<option v-for="option in typeOptions" :value="option.value" :key="option.value">
									{{ option.text }}
								</option>
							</select>
						</uni-th>
						<uni-th align="center">
							<view @click="exportToExcel">导出Excel</view>
						</uni-th>
						<uni-th width="204" align="center">
							<view @click="exportAllToExcel">All导出Excel</view>
						</uni-th>
					</uni-tr>

				</uni-thead>

				<uni-tr>
					<uni-th width="150" align="center">日期</uni-th>
					<uni-th width="150" align="center">工序</uni-th>
					<uni-th align="center">&nbsp;</uni-th>
					<uni-th width="204" align="center">数量</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.date }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.group }}</view>
					</uni-td>
					<uni-td align="center">&nbsp;</uni-td>
					<uni-td align="center">
						{{ item.count }}
					</uni-td>
				</uni-tr>



			</uni-table>
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent"
					:total="total" @change="change" /></view>
		</view>
	</view>
</template>

<script>
	import axios from 'axios';
	import tableData from './tableData.js'
	import * as XLSX from 'xlsx';
	import {
		saveAs
	} from 'file-saver';
	export default {
		data() {
			return {
				searchVal: '',
				tableData: [],
				// 每页数据量
				pageSize: 25,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false,
				//日期
				currentDate: new Date(),
				//保养
				dataBaoyang: [],
				//分组数据
				groupData: [],
				//计算字典
				countDic: {},
				//
				typeData: "../../保养数据格式.json", //点检数据格式.json,设备维修数据格式.json
				//下拉框
				selected: '',
				options: [{
						value: '1',
						text: '保养'
					},
					{
						value: '2',
						text: '点检'
					},
					{
						value: '3',
						text: '维修'
					}
				],
				typeSelected: '1',
				typeOptions: [{
						value: '1',
						text: '员工'
					},
					{
						value: '2',
						text: '工序'
					}
				],
				//对应关系
				//保养组编码	保养组名称	所属员工号	所属员工名称
				peopleMap: [{
						no: 'YD00150',
						group: 'DI_编带(片感)',
						pno: 'YD00150',
						name: '李钦章'
					},
					
					 
					{
						no: 'DC-FD-WX-01',
						group: '封端烧端',
						pno: 'HF-FD-JX01',
						name: '黎伟锋'
					}, {
						no: 'DC-FD-WX-01',
						group: '封端烧端',
						pno: 'HF-FD-JX02',
						name: '邹仲强'
					}, {
						no: 'DC-FD-WX-01',
						group: '封端烧端',
						pno: 'HF-FD-JX03',
						name: '黎伟锋'
					}, {
						no: 'DC-FD-WX-01',
						group: '封端烧端',
						pno: 'HF-FD-JX01',
						name: '黎富恒'
					}, {
						no: 'DC-FD-WX-01',
						group: '封端烧端',
						pno: 'HF-FD-JX01',
						name: '黎伟锋'
					}, {
						no: 'DC-DD-WX-01',
						group: '沉积线\离心机\钢珠分选机',
						pno: 'HF-DD-JX01',
						name: '马明锋'
					}, {
						no: 'DC-DD-WX-01',
						group: '沉积线\离心机\钢珠分选机',
						pno: 'HF-DD-JX02',
						name: '吴永健'
					},
					{
						no: 'DC-CS-WX-01',
						group: 'DF_外观测试(片感)',
						pno: 'HF-CS-JX01',
						name: '赵伟锋'
					}, {
						no: 'DC-CS-WX-01',
						group: 'DF_外观测试(片感)',
						pno: 'HF-CS-JX02',
						name: '覃基发'
					}, {
						no: 'DC-CS-WX-01',
						group: 'DF_外观测试(片感)',
						pno: 'HF-CS-JX03',
						name: '郑军平'
					}, {
						no: 'DC-CS-WX-01',
						group: 'DF_外观测试(片感)',
						pno: 'HF-CS-JX04',
						name: '罗星威'
					}, {
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX01',
						name: '陈志威'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX02',
						name: '朱楷城'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX03',
						name: '黎健林'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX04',
						name: '梁伟均'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX05',
						name: '李金良'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX06',
						name: '莫志杰'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX07',
						name: '李文文'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX08',
						name: '谢颖通'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX09',
						name: '李波源'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX10',
						name: '陈锡漫'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX11',
						name: '李晓通'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX12',
						name: '董梓浩'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX13',
						name: '赵敏羽'
					},
					{
						no: 'DC-BD-WX-01',
						group: 'DI_编带(片感)',
						pno: 'HF-BD-JX14',
						name: '黄其军'
					},
					{
						no: '1',
						group: 'DW_干法丝印',
						pno: '1',
						name: '詹承振'
					},
					{
						no: 'DC-GF-BY-01',
						group: '砂磨流延切膜',
						pno: 'GF-JX01',
						name: '梁金尧'
					},
					{
						no: 'DC-GF-BY-01',
						group: '砂磨流延切膜',
						pno: 'GF-JX04',
						name: '钟文辉'
					},
					{
						no: 'DC-GF-BY-01',
						group: '砂磨流延切膜',
						pno: 'GF-JX07',
						name: '王德庭'
					},
					{
						no: 'DC-GF-BY-02',
						group: 'DX_干法打孔',
						pno: 'GF-JX05',
						name: '陈猛'
					},
					{
						no: 'DC-GF-BY-02',
						group: 'DX_干法打孔',
						pno: 'GF-JX03',
						name: '陈启荣'
					},
					{
						no: 'DC-GF-BY-02',
						group: 'DX_干法打孔',
						pno: 'GF-JX06',
						name: '赖富贵'
					},
					{
						no: 'DC-GF-BY-03',
						group: 'DW_干法丝印',
						pno: 'GF-JX02',
						name: '曾东红'
					},
					{
						no: 'DC-GF-BY-03',
						group: 'DW_干法丝印',
						pno: 'GF-JX04',
						name: '钟文辉'
					},
					{
						no: 'DC-GF-BY-03',
						group: 'DW_干法丝印',
						pno: 'GF-JX08',
						name: '莫铭辉'
					},
					{
						no: 'DC-GF-BY-03',
						group: 'DW_干法丝印',
						pno: 'GF-JX07',
						name: '王德庭'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX03',
						name: '陈启荣'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX01',
						name: '梁金尧'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX02',
						name: '曾东红'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX06',
						name: '赖富贵'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX08',
						name: '莫铭辉'
					},
					{
						no: 'DC-GF-BY-05',
						group: '黄光',
						pno: 'GF-JX05',
						name: '陈猛'
					},
					{
						no: '2',
						group: '烧炉组',
						pno: '2',
						name: '李国忠'
					},
					{
						no: 'IN002261',
						group: 'DI_编带(片感)',
						pno: 'IN002261',
						name: '肖光'
					},
					{
						no: 'DC-SL-WX-01',
						group: '烧炉组',
						pno: 'HF-SL-JX01',
						name: '莫小佳'
					},
					{
						no: 'DC-SL-WX-01',
						group: '烧炉组',
						pno: 'HF-SL-JX02',
						name: '伍正宇'
					},
					{
						no: 'DC-SL-WX-01',
						group: '烧炉组',
						pno: 'HF-SL-JX03',
						name: '吴晋锋'
					},
					{
						no: 'DC-CX-WX-01',
						group: '成型组',
						pno: 'HF-CX-JX01',
						name: '刘德友'
					},
					{
						no: 'DC-CX-WX-02',
						group: '成型组',
						pno: 'HF-CX-JX02',
						name: '梁启明'
					},
					{
						no: 'DC-CX-WX-03',
						group: '成型组',
						pno: 'HF-CX-JX03',
						name: '高超'
					},
					{
						no: 'DC-CX-WX-04',
						group: '成型组',
						pno: 'HF-CX-JX04',
						name: '蔡永恒'
					},
					{
						no: 'DC-CX-WX-05',
						group: '成型组',
						pno: 'HF-CX-JX05',
						name: '邹信林'
					},
					{
						no: 'DC-CX-WX-06',
						group: '成型组',
						pno: 'HF-CX-JX06',
						name: '李元泽'
					},
					{
						no: 'DC-CX-WX-07',
						group: '成型组',
						pno: 'HF-CX-JX07',
						name: '黎鸿斌'
					},
					{
						no: 'DC-CX-WX-08',
						group: '成型组',
						pno: 'HF-CX-JX08',
						name: '颜俊庭'
					},
					//补充一些
					{
						no: 'DC-GF-BY-03',
						group: 'DV_干法成型',
						pno: 'GF-JX09',
						name: '饶铭飞'
					},
					{
						no: 'DC-GF-BY-04',
						group: 'DV_干法成型',
						pno: 'GF-JX10',
						name: '杜俊标'
					},
					{
						no: 'DC-GF-BY-05',
						group: 'DV_干法成型',
						pno: 'GF-JX11',
						name: '梁栩明'
					},
					{
						no: 'zdx',
						group: '切割',
						pno: 'zdx',
						name: '晏文龙'
					},
					{
						no: 'zdx',
						group: '流延',
						pno: 'zdx',
						name: 'zdx'
					},
					{
						no: '002',
						group: '成型组',
						pno: '002',
						name: '吴运生'
					},
					{
						no: 'DC-GF-BY-03',
						group: 'DW_干法丝印',
						pno: 'GF-JX010',
						name: '李敬轩'
					},
					{
						no: 'msz',
						group: 'DX_干法打孔',
						pno: 'GF-JX011',
						name: '莫世展'
					},
					{
						no: 'msz',
						group: 'DV_干法成型',
						pno: 'GF-JX012',
						name: '区键伟'
					},
					{
						no: 'PG-001',
						group: '品管',
						pno: 'PG-001',
						name: '叶夏珍'
					},
					{
						no: 'PG-002',
						group: '品管',
						pno: 'PG-002',
						name: '黄翠英'
					},
					{
						no: 'PG-003',
						group: '品管',
						pno: 'PG-003',
						name: '李秀英'
					},
					{
						no: 'PG-004',
						group: '品管',
						pno: 'PG-004',
						name: '胡小凤'
					},
					{
						no: 'PG-005',
						group: '品管',
						pno: 'PG-005',
						name: '祁世博'
					},
					{
						no: 'PG-006',
						group: '品管',
						pno: 'PG-006',
						name: '朱小旋'
					},
					{
						no: 'PG-007',
						group: '品管',
						pno: 'PG-007',
						name: '陈子鹏'
					},
					
					{
						no: 'SL-001',
						group: '烧炉组',
						pno: 'SL-001',
						name: '张丽诗'
					},
					{
						no: 'ZDH-001',
						group: '设备自动化',
						pno: 'ZDH-001',
						name: '梁晓琴'
					},
					
					
					{
							no: 'BD17',
							group: 'DI_编带(片感)',
							pno: 'BD17',
							name: '莫本慰'
						},
					{
						no: 'SY1',
						group: 'DW_干法丝印',
						pno: 'SY1',
						name: '罗金正'
						
					},
					{
						no: 'SM1',
						group: 'SM_干法砂磨',
						pno: 'SM1',
						name: '梁嘉杰'
						
					},
					{
						no: 'BD18',
						group: 'DI_编带(片感)',
						pno: 'BD18',
						name: '阮燕婷'
						
					},
					{
						no: 'GF-JX018',
						group: 'DX_干法打孔',
						pno: 'GF-JX018',
						name: '林道曾'
					},

				],
				//资产编码  工序位置
				devMap:[
					// {   group: 'DI_编带(片感)',
					// 	pno: 'YD00150',
					// 	name: '李钦章'
					// }
				],
				//保养数据源
				urby1: "http://10.20.212.43/rest/cpm_tasks/queryMachPmTask?select=id%2Cpm_plan%2Cpm_plan_ver%2Cname%2Cres%2Cplan_time%2Cstatus%2Ccheck_time%2Cmonitor_lot_id%2Cmonitor_lot_trace_seq%2Calarm1_id%2Calarm_duration_1%2Calarm2_id%2Calarm_duration_2%2Calarm3_id%2Calarm_duration_3%2Csegment3_id%2Csegment4_id%2Csegment5_id%2Cres_type%2Ctask_type%2Cupdater%2Cupdated_at%2Csegment20_id&sort=%5B%7B%22field%22%3A%22updated_at%22%2C%22ascending%22%3Afalse%7D%5D&query=%5B%7B%22name%22%3A%22workshop_id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%221853240895667834880%22%7D%2C%7B%22name%22%3A%22task_type%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%22WB%22%7D%5D&page=1&limit=1000",
				urdj1: "http://10.20.212.43/rest/mach_checks?select=id%2Cname%2Cdescription%2Cmach%2Ccheck_date%2Cstatus%2Cclasses%2Ccheck_type%2Csegment1_id%2Csegment2%2Cupdater%2Cupdated_at%2Cplan_id&sort=%5B%7B%22field%22%3A%22updated_at%22%2C%22ascending%22%3Afalse%7D%5D&query=%5B%7B%22name%22%3A%22segment2_id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%221853240895667834880%22%7D%5D&page=1&limit=1000",
				urlwx1: "http://10.20.212.43/rest/mach_repairs?select=id%2Csite_id%2Cmach%2Cstatus%2Crepair_action%2Crepair_code%2Cremark%2Csegment1_id%2Csegment2_id%2Csegment3%2Csegment4%2Cupdater%2Cupdated_at%2Csegment6_id%2Csegment7&sort=%5B%7B%22field%22%3A%22updated_at%22%2C%22ascending%22%3Afalse%7D%5D&query=%5B%7B%22name%22%3A%22segment7_id%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%221853240895667834880%22%7D%5D&page=1&limit=1000",
				local_urby1: "保养数据格式.json",
				local_urldj1: "点检数据格式.json",
				local_urlwx1: "设备维修数据格式.json",
				historyPrefix:'',//历史数据源前缀（../../old/12-31/）
				sumDC:{},//把叠层制造统计起来
			}
		},
		computed: {
			// 计算本周一日期
			mondayDate() {
				let monday = new Date(this.currentDate);
				monday.setDate(monday.getDate() - monday.getDay() + 1);
				return monday.toLocaleDateString();
			},
			// 计算本周日日期
			sundayDate() {
				let sunday = new Date(this.currentDate);
				sunday.setDate(sunday.getDate() - sunday.getDay() + 7);
				return sunday.toLocaleDateString();
			}
		},
		mounted() {

		},
		onLoad() {
			this.appendDev();
			this.appendPeoPle();
			this.selectedIndexs = []
			// this.getData(1)
		},
		created() {
			var that = this;
			this.readData(function(data) {
				that.getData(1)
			});
		},
		methods: {
			// 多选处理
			selectedItems() {
				return this.selectedIndexs.map(i => this.tableData[i])
			},
			// 多选
			selectionChange(e) {
				console.log(e.detail.index)
				this.selectedIndexs = e.detail.index
			},
			//批量删除
			delTable() {
				console.log(this.selectedItems())
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.getData(e.current)
			},
			// 搜索
			search() {
				this.getData(1, this.searchVal)
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.loading = true
				this.pageCurrent = pageCurrent
				this.request({
					pageSize: this.pageSize,
					pageCurrent: pageCurrent,
					value: value,
					success: res => {
						// console.log('data', res);

						this.tableData = res.data
						this.total = res.total
						this.loading = false
					}
				})
			},
			// 伪request请求
			request(options) {
				const {
					pageSize,
					pageCurrent,
					success,
					value
				} = options
				var tempArr = this.dataBaoyang;
				if (this.typeSelected == "1") {
					tempArr = this.dataBaoyang;
				} else if (this.typeSelected == "2") {
					tempArr = this.groupData;
				}
				let total = tempArr.length
				let data = tempArr.filter((item, index) => {
					const idx = index - (pageCurrent - 1) * pageSize
					return idx < pageSize && idx >= 0
				})
				if (value) {
					data = []
					tempArr.forEach(item => {
						if (item.name.indexOf(value) !== -1) {
							data.push(item)
						}
					})
					total = data.length
				}

				setTimeout(() => {
					typeof success === 'function' &&
						success({
							data: data,
							total: total
						})
				}, 500)
			},
			readData(callback) {
				
				var that = this;
				axios.get(this.typeData)
					.then(response => {
						this.tableData = response.data;
						this.dataBaoyang = [];
						this.countDic = {};
						//分组数据
						this.groupData = [];
						response.data.items.forEach(function(element) {
							var it = {
								"date": element.check_time,
								"name": element.updater.name,
								"address": element.res.name,
								"count": 1,
								"group": that.mapGroup(element.updater.name,element.res.name)
							};
							that.dataBaoyang.push(it)
							that.countNum(it);
						}, this);
						this.groupByGx();
						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(this.dataBaoyang);
							}, 500)

						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			readData1(callback) {
				
				var that = this;
				axios.get(this.typeData)
					.then(response => {
						this.tableData = response.data;
						this.dataBaoyang = [];
						this.countDic = {};
						//分组数据
						this.groupData = [];

						response.data.items.forEach(function(element) {
							var it = {
								"date": element.check_date,
								"name": element.updater.name,
								"address": element.mach.name,
								"count": 1,
								"group": that.mapGroup(element.updater.name,element.mach.name)
							};
							this.dataBaoyang.push(it)
							that.countNum(it);
						}, this);
						this.groupByGx();
						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(this.dataBaoyang);
							}, 500)

						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			readData2(callback) {
				
				var that = this;
				axios.get(this.typeData)
					.then(response => {
						this.tableData = response.data;
						this.dataBaoyang = [];
						this.countDic = {};
						//分组数据
						this.groupData = [];
						response.data.items.forEach(function(element) {
							try {
								if(typeof element.updater !='undefined'){
								var it = {
									"date": element.updated_at,
									"name": element.updater.name,
									"address": element.mach.name,
									"count": 1,
									"group": that.mapGroup(element.updater.name,element.mach.name)
								};
								this.dataBaoyang.push(it);	
								}else{
									console.log('updater undefined');
									var it = {
										"date": element.updated_at,
										"name": element.main_end_user,
										"address": element.mach.name,
										"count": 1,
										"group": that.mapGroup(element.main_end_user,element.mach.name)
									};
									this.dataBaoyang.push(it);	
								}
								
							} catch (error) {
								//TODO handle the exception
								console.log(error);
							}
							if(typeof it !='undefined'&& typeof it.group !='undefined'){
								that.countNum(it);
							}else{
								console.log('group undefined');
							}
							
						}, this);
						this.groupByGx();

						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(this.dataBaoyang);
							}, 500)

						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			handleSelectChange(e) {

				var that = this;
				if (this.selected == "1") {
					this.typeData = this.getlocal_urby1();
					this.readData(function(data) {
						that.getData(1)
					});
				} else if (this.selected == "2") {
					this.typeData = this.getlocal_urldj1();
					this.readData1(function(data) {
						that.getData(1)
					});
				} else if (this.selected == "3") {
					this.typeData = this.getlocal_urlwx1();
					this.readData2(function(data) {
						that.getData(1)
					});
				}
			},
			mapGroup(name,address) {
				var gx = "叠层制造";
				//如果知不道对应工序
				gx=this.mapDevGroup(address);

				
				if (gx == "叠层制造") {
					// console.log(name, this.peopleMap.length);
					for (var i = 0; i < this.peopleMap.length; i++) {
						if (name == this.peopleMap[i].name) {
							gx = this.peopleMap[i].group;
							break;
						}
					
					}
				
				}
				
				
				
				return gx;
			},
			mapDevGroup(name){
				//保养 
				//点检
				//维修
				// if(name=='DG-2024-0466'){
				// 					debugger
				// 	console.log('倒角-----------',this.devMap.length);
				// }
				var gx = "叠层制造";
				for (var i = 0; i < this.devMap.length; i++) {
					
					
					if (name == this.devMap[i].name) {
						gx = this.devMap[i].group;
						this.sumDC[name]="";//
						break;
					}
				
				}
				if (gx == "叠层制造") {
					this.sumDC[name]=name;
					// console.log(Object.values(this.sumDC));
				
				}
				return gx;
			},
			handleStypeSelectChange(e) {
				var that = this;
				this.handleSelectChange(this.selected)
			},
			//根据工序分组统计
			groupByGx(groupData) {
				var re = [];
				if (typeof groupData != "undefined") {
					for (const key in this.countDic) {
						groupData.push(this.countDic[key]);
					}
					re = groupData;
				} else {
					for (const key in this.countDic) {
						this.groupData.push(this.countDic[key]);
					}
					re = this.groupData;
				}

				return re;

			},
			//统计数量
			countNum(item) {
				var re = this.countDic[item.group];
				if(item.group=='叠层制造')
				{
					console.log('countNum',item);
				}
				//第一个
				if (typeof re == "undefined") {
					if(typeof item.group=='undefined'||null==item.group||item.group==""){
						console.log(item);
					}else{
						this.countDic[item.group] = {
							"date": item.date,
							"name": item.name,
							"address": item.address,
							"group": item.group,
							"count": 1
						}
					}
					
					
					//存在
				} else {
					re.count++;
				}
				return re;
			},
			//导出excel
			exportToExcel() {
				// 假设你有一个表格数据的数组

				var filename = "员工分组";
				var prix = (this.selected == "1" ? "保养" : (this.selected == "2" ? "点检" : "维修"));
				var tempArr = this.dataBaoyang;
				if (this.typeSelected == "1") {
					tempArr = this.dataBaoyang;
					filename = "员工分组";
					var data = [
						["日期", "员工", "机台", "工序"],
					];
					for (var i = 0; i < tempArr.length; i++) {
						data.push([tempArr[i].date, tempArr[i].name, tempArr[i].address, tempArr[i].group]);
					}
				} else if (this.typeSelected == "2") {
					tempArr = this.groupData;
					filename = "岗位分组";
					var data = [
						["日期", "工序", "数量"],
					];
					for (var i = 0; i < tempArr.length; i++) {
						data.push([tempArr[i].date, tempArr[i].group, tempArr[i].count]);
					}
				}


				// 将数据转换为工作表
				const worksheet = XLSX.utils.aoa_to_sheet(data);

				// 创建工作簿并添加工作表
				const workbook = XLSX.utils.book_new();
				XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

				// 生成Excel文件
				const excelBuffer = XLSX.write(workbook, {
					bookType: 'xlsx',
					type: 'array'
				});

				// 使用blob和FileReader创建一个Blob URL
				const dataBlob = new Blob([excelBuffer], {
					type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'
				});
				const blobUrl = window.URL.createObjectURL(dataBlob);

				// 使用saveAs下载文件
				saveAs(dataBlob, prix + "_" + filename + 'export' + (new Date().toLocaleDateString()) + '.xlsx');

				// 清理
				window.URL.revokeObjectURL(blobUrl);
			},
			data1(callback) {
				var that = this;
				var byArr = []; //保养
				this.countDic = {}; //清理
				axios.get(this.getlocal_urby1())
					.then(response => {
						if (response.data.items == null) {
							if (typeof callback != 'undefined') {
								setTimeout(() => {
									callback(byArr);
								}, 50);
							}
						}
						response.data.items.forEach(function(element) {
							var it = {
								"date": element.check_time,
								"name": element.updater.name,
								"address": element.res.name,
								"count": 1,
								"group": that.mapGroup(element.updater.name,element.res.name)
							};
							that.countNum(it);
						}, that);
						byArr = that.groupByGx(byArr);
						console.log(byArr)
						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(byArr);
							}, 500);
						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			data2(callback) {
				var that = this;
				var djArr = []; //点检
				this.countDic = {}; //清理
				//点检
				axios.get(that.getlocal_urldj1())
					.then(response => {
						if (response.data.items == null) {
							if (typeof callback != 'undefined') {
								setTimeout(() => {
									callback(djArr);
								}, 50);
							}
						}
						response.data.items.forEach(function(element) {
							var it = {
								"date": element.check_date,
								"name": element.updater.name,
								"address": element.mach.name,
								"count": 1,
								"group": that.mapGroup(element.updater.name,element.mach.name)
							};
							that.countNum(it);
						}, that);
						
						djArr = that.groupByGx(djArr);
						console.log(djArr);
						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(djArr);
							}, 500);
						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			data3(callback) {
				var that = this;
				var wxArr = []; //维修
				this.countDic = {}; //清理
				//维修
				axios.get(that.getlocal_urlwx1())
					.then(response => {
						if (response.data.items == null) {
							if (typeof callback != 'undefined') {
								setTimeout(() => {
									callback(wxArr);
								}, 50);
							}
						}
						response.data.items.forEach(function(element) {
							
							if(typeof element.updater !='undefined'){
							var it = {
								"date": element.updated_at,
								"name": element.updater.name,
								"address": element.mach.name,
								"count": 1,
								"group": that.mapGroup(element.updater.name,element.mach.name)
							};
							this.dataBaoyang.push(it);	
							}else{
								console.log('updater undefined');
								var it = {
									"date": element.updated_at,
									"name": element.main_end_user,
									"address": element.mach.name,
									"count": 1,
									"group": that.mapGroup(element.main_end_user,element.mach.name)
								};
								this.dataBaoyang.push(it);	
							}
							that.countNum(it);
						}, that);
						wxArr = that.groupByGx(wxArr);
						console.log(wxArr);
						if (typeof callback != 'undefined') {
							setTimeout(() => {
								callback(wxArr);
							}, 500);
						}
					})
					.catch(error => {
						console.log(error);
					});




			},
			//全部导出
			exportAllToExcel() {
				var that = this;
				that.data1(function(byArr) {
					that.data2(function(djArr) {
						that.data3(function(wxArr) {
							that.AllExp(byArr, djArr, wxArr);
						});
					});
				})

			},
			AllExp(byArr, djArr, wxArr) {
				console.log("export", byArr.length, djArr.length, wxArr.length);
				//key: "value",
				var bydata = [
					["日期", "工序", "数量"],
				];
				for (var i = 0; i < byArr.length; i++) {
					bydata.push([byArr[i].date, byArr[i].group, byArr[i].count]);
				}

				var djdata = [
					["日期", "工序", "数量"],
				];
				for (var i = 0; i < djArr.length; i++) {
					djdata.push([djArr[i].date, djArr[i].group, djArr[i].count]);
				}

				var wxdata = [
					["日期", "工序", "数量"],
				];
				for (var i = 0; i < wxArr.length; i++) {
					wxdata.push([wxArr[i].date, wxArr[i].group, wxArr[i].count]);
				}


				// 将数据转换为工作表
				const worksheet = XLSX.utils.aoa_to_sheet(bydata);
				// 创建工作簿并添加工作表
				const workbook = XLSX.utils.book_new();
				XLSX.utils.book_append_sheet(workbook, worksheet, '保养');

				const worksheet2 = XLSX.utils.aoa_to_sheet(djdata);
				XLSX.utils.book_append_sheet(workbook, worksheet2, '点检');

				const worksheet3 = XLSX.utils.aoa_to_sheet(wxdata);
				XLSX.utils.book_append_sheet(workbook, worksheet3, '维修');

				// 生成Excel文件
				const excelBuffer = XLSX.write(workbook, {
					bookType: 'xlsx',
					type: 'array'
				});

				// 使用blob和FileReader创建一个Blob URL
				const dataBlob = new Blob([excelBuffer], {
					type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'
				});
				const blobUrl = window.URL.createObjectURL(dataBlob);

				var name=this.historyPrefix!=''?this.historyPrefix:(new Date().toLocaleDateString());
				//saveAs下载文件
				saveAs(dataBlob, 'export' + name + '.xlsx');

				// 清理
				window.URL.revokeObjectURL(blobUrl);
			},
			appendPeoPle() {
				if (this.peopleMap.length < 100) {
					this.loadTextFile('../../peo.txt'); //加载人员数组
				}
			},
			appendDev() {
				
				if (this.devMap.length < 100) {
					this.loadTextFileDev('../../devices.text'); //加载人员数组
				}
			},
			expGX(){
				
				console.log('-----工序-----');
				var str='';
				for (var i = 0; i < this.peopleMap.length; i++) {
					console.log(this.peopleMap[i].group);
				}
				console.log('-----工序-----');
			},
			loadTextFile(filePath) {
				fetch(filePath)
					.then(response => response.text())
					.then(text => {
						this.textContent = text;
						this.getarr();
					})
					.catch(error => {
						console.error('Error reading file:', error);
					});
			},
			getarr() {
				var arr = this.textContent.split("\n")

				for (var i = 0; i < arr.length; i++) {
					var line = arr[i];
					var arr2 = line.split("\t");

					this.peopleMap.push({
						no: arr2[0],
						group: arr2[1],
						pno: arr2[2],
						name: arr2[3]
					})
				}
				console.log(this.peopleMap);
			},
			
			loadTextFileDev(filePath) {
				fetch(filePath)
					.then(response => response.text())
					.then(text => {
						
						this.textContent1 = text;
						this.getarrDev();
					})
					.catch(error => {
						console.error('Error reading file:', error);
					});
			},
			getarrDev() {
				
				var arr = this.textContent1.split("\n")
			
				for (var i = 0; i < arr.length; i++) {
					var line = arr[i];
					var arr2 = line.split("\t");
					// if(arr2[0]=='DG-2023-0427'){
						this.devMap.push({
							no: arr2[0],
							group: arr2[1],
							pno: arr2[1],
							name: arr2[0]
						})
					// }
					
				}
				console.log(this.devMap);
			},
			getlocal_urby1(){
				if(this.historyPrefix!=''){
					return '../../old/'+this.historyPrefix+'/'+this.local_urby1;
				}else{
					return '../../'+this.local_urby1;
				}
			},
			getlocal_urldj1(){
				if(this.historyPrefix!=''){
					return '../../old/'+this.historyPrefix+'/'+this.local_urldj1;
				}else{
					return '../../'+this.local_urldj1;
				}
			},
			getlocal_urlwx1(){				
				if(this.historyPrefix!=''){
					return '../../old/'+this.historyPrefix+'/'+this.local_urlwx1;
				}else{
					return '../../'+this.local_urlwx1;
				}
			}
		}
	}
</script>

<style>
	/* #ifndef H5 */
	/* page {
	padding-top: 85px;
} */
	/* #endif */
	.uni-group {
		display: flex;
		align-items: center;
	}
</style>